package cz.data.gateway.model.dto;

import cz.data.common.core.DataConstant;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Getter
@Setter
@ToString
public class RouteDefinitionDto {
    public static final String DEFINITION_NAME_KEY = "_description";
    public static final String STATUS_KEY = "_active";
    public static final String REMOVE_KEY = "_remove";
    public static final String CREATOR_KEY = "_creator";

    @ApiModelProperty(value = "网关路由id")
    private String id;
    @ApiModelProperty(value = "路由ID")
    private String routeId;
    @ApiModelProperty(value = "网关断言")
    private List<PredicateDefinitionDto> predicates = new ArrayList<>();
    @ApiModelProperty(value = "网关过滤器信息")
    private List<FilterDefinitionDto> filters = new ArrayList<>();
    @ApiModelProperty(value = "网关uri")
    private URI uri;
    @ApiModelProperty("网关路由元数据")
    private Map<String, Object> metadata = new HashMap<>();
    @ApiModelProperty(value = "路由排序")
    private int order = 0;
    public void activeRoute(String status) {
        if (DataConstant.TrueOrFalse.TRUE.equalsKey(status)) {
            this.metadata.put(STATUS_KEY, true);
        } else {
            this.metadata.put(STATUS_KEY, false);
        }
    }

    public void inactiveRoute() {
        this.metadata.put(STATUS_KEY, false);
    }

    public void description(String description) {
        this.metadata.put(DEFINITION_NAME_KEY, description);
    }

    public void creator(String creator) {
        this.metadata.put(CREATOR_KEY, creator);
    }

    public boolean remove() {
        return this.metadata.containsKey(REMOVE_KEY);
    }
}
